package com.example.common;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private Integer pageNumber;       // 当前页码
    private Integer pageSize;         // 每页大小
    private Integer pages;       // 总页数
    private Long totals;    // 总记录数
    private List<T> list;   // 分页数据

    public PageResult(Page<T> page) {
        this.pageNumber = page.getPageNum();
        this.pageSize = page.getPageSize();
        this.pages = page.getPages();
        this.totals = page.getTotal();
        this.list = page.getResult();
    }

    public PageResult(PageInfo<T> pageInfo) {
        this.pageNumber = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.pages = pageInfo.getPages();
        this.totals = pageInfo.getTotal();
        this.list = pageInfo.getList();
    }
}

